package com.wzx.user.controller;

import com.alipay.api.AlipayApiException;
import com.wzx.common.exception.LeadNewsException;
import com.wzx.common.pojo.resp.Result;
import com.wzx.user.service.WalletService;
import com.wzx.user.vo.NotesVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author wzx
 * @version 1.0
 * @date 2023/3/1 - 22:36
 * @description 标题
 */
@Slf4j
@RestController
@RequestMapping("/wallet")
@Api(tags = "用户余额信息")
public class WalletController {

    @Autowired
    private WalletService walletService;

    @GetMapping("/queryBalance")
    @ApiOperation(value = "查询余额")
    public Result<Double> queryBalance(Integer userId) throws Exception {
        double result = walletService.queryBalance(userId);
        return Result.ok(result);
    }

    @PostMapping("/addBalance")
    @ApiOperation(value = "添加余额")
    public Result addBalance(@RequestBody NotesVo notesVo){
        walletService.addBalance(notesVo);
        return Result.ok();
    }

    @PostMapping("/cashWithdrawal")
    @ApiOperation(value = "提取现金")
    public Result<String> cashWithdrawal(@RequestBody NotesVo notesVo) throws LeadNewsException, AlipayApiException {
        String reuslt = walletService.cashWithdrawal(notesVo);
        return Result.ok(reuslt);
    }

    @PostMapping("/updatePwd")
    @ApiOperation(value = "修改支付密码")
    public Result updatePwd(@RequestBody NotesVo notesVo) throws LeadNewsException {
        walletService.updatePwd(notesVo);
        return Result.ok();
    }

    @PostMapping("/forgetPwd")
    @ApiOperation(value = "忘记支付密码")
    public Result forgetPwd(@RequestBody NotesVo notesVo) throws LeadNewsException {
        walletService.forgetPwd(notesVo);
        return Result.ok();
    }

    @PostMapping("/judgePwd")
    @ApiOperation(value = "判断支付密码是否正确")
    public Result<Boolean> judgePwd(@RequestBody NotesVo notesVo) throws LeadNewsException {
        Boolean b = walletService.judgePwd(notesVo);
        return Result.ok(b);
    }
}
